package edu.friday.common.security.service;

import edu.friday.model.vo.SysUserVo;
import edu.friday.service.SysMenuService;
import edu.friday.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashSet;
import java.util.Set;

@Component
public class SysPermissionService {
    @Autowired
    private SysRoleService sysRoleService;
    @Autowired
    private SysMenuService sysMenuService;

    public Set<String> getMenuPermission(SysUserVo user){
        Set<String> menuPermissions = new HashSet<String>();
        if (user.isAdmin()){
            menuPermissions.add("*:*:*");
        }else {
            menuPermissions.addAll(sysMenuService.selectMenuPermsByUserId(user.getId()));
        }
        return menuPermissions;
    }

    public Set<String> getRolePermission(SysUserVo user){
        Set<String> menuPermissions = new HashSet<String>();
        if (user.isAdmin()){
            menuPermissions.add("*:*:*");
        }else {
            menuPermissions.addAll(sysRoleService.selectRolePermissionByUserId(user.getId()));
        }
        return menuPermissions;
    }
}
